<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!-- computed 计算属性，本质上面还是属性，写法如函数，命名如属性-->
<body>
    <div id="app">

        <!-- 原始的方案 -->
        <p>会员总积分：{{members[0].score + members[1].score + members[2].score  + members[3].score }}</p>

        <!-- 通过计算属性获取到 -->
        <p>会员总积分：{{totalScore}}</p>
    </div>
    <script src="js/vue.js"></script>

    <script>
        const HelloVue = {
            data(){
                return {
                    members:[
                        {id:"0001", name:"张三", score: 13232},
                        {id:"0002", name:"王五", score: 14232},
                        {id:"0003", name:"李四", score: 15232},
                        {id:"0004", name:"赵六", score: 16232},
                    ]
                }
            },
            // 计算属性
            computed:{
                /* 细节：本质上面还是属性，写法如函数，命名如属性 */
                totalScore(){
                    let total = 0;
                    this.members.forEach(element => {
                        total += element.score;
                    });
                    return total;
                }
            },
            methods: {
              
            }
        };

        const app = Vue.createApp(HelloVue).mount("#app");
       
    </script>
</body>
</html>